package aidturith.ihm.component;

import java.awt.FlowLayout;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JTextField;

import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

public class AutoCompleteTextField extends JTextField {

	private static final long serialVersionUID = 1L;
	private ArrayList<Object> list = new ArrayList<Object>();

	public AutoCompleteTextField(int column, ArrayList<Object> list, boolean matching) {
		super(column);
		this.list = list;
		AutoCompleteDecorator.decorate(this, getList(), matching);
	}

	public ArrayList<Object> getList() { return list; }
	public void setList(ArrayList<Object> list) { this.list = list; }

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		ArrayList<Object> list = new ArrayList<Object>();
		list.add("test");
		list.add("cat");
		list.add("dog");

		AutoCompleteTextField tf = new AutoCompleteTextField(30, list, false);
		frame.add(tf);
		frame.setLayout(new FlowLayout());
		frame.setVisible(true);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
